<template>
    <div id="app">
        <!-- 登录 -->
        <div class="dh_xgj-register" v-if="!bussdata">
            <form action="" class="d_x-reg-form">

                <h3>商户录入系统</h3>

                <div class="d_x-r-f-text">
                    <i class="dx-rft-log unameicon" aria-hidden="true"></i>
                    <input id="int-name" tyep="text" max="18" min="6" name="uname" placeholder="账号" v-model="login.uname"/>
                    <label for="int-name" class="dx-rft-label"></label>
                </div>

                <div class="d_x-r-f-text">
                    <i class="dx-rft-log pwdicon" aria-hidden="true"></i>
                    <input id="int-pwd" :type="typepwd" max="18" min="6" name="pwd" placeholder="密码" v-model="login.pwd" autocomplete="off" @input="examine" />
                    <i v-if="examinestate" @click="checkpwd" class="dx-rft-eye"></i>
                    <label for="int-pwd" class="dx-rft-label"></label>
                </div>

                
                <div class="d_x-r-f-btn">
                    <span class="red">{{login.text}}</span>
                </div>

                <el-button class="dx-rft-btn" slot="reference" @click="register" @keyup.13.native="register">登录</el-button>

            </form>
        </div>
        <!-- 
            后台数据
         -->
        <div class="dh_xgj-content" v-else>
            <!-- 侧边导航栏 -->
            <div class="d_x-c-navigation">
				  
                <el-menu 
                    :default-active="$route.path"  
                    router 
                    @select="handleSelect" 
                    class="el-menu-vertical-demo"
                    height="500"
                    background-color="#20222A"
                    active-text-color="#fff"
                    v-if="bussdata.level === 1"
                >
                    <el-menu-item disabled>
                        <span slot="title">支付宝商户管理</span>
                    </el-menu-item>	

                    <el-menu-item :index="item.link.toString()" v-for="(item,indexa) in navioption" :key="indexa"  @click="navBar(item,indexa)">
                        <i :class="item.icon"></i>
                        <span slot="title" :class="(item.name.length === 3 ? 'ws24' : '')">{{item.name}}</span>
                    </el-menu-item>	

                </el-menu>

                <el-menu 
                    :default-active="$route.path"  
                    router 
                    @select="handleSelect" 
                    class="el-menu-vertical-demo"
                    height="500"
                    background-color="#20222A"
                    active-text-color="#fff"
                    v-else
                >
                    <el-menu-item disabled>
                        <span slot="title">支付宝商户管理</span>
                    </el-menu-item>	

                    <el-menu-item :index="item.link.toString()" v-for="(item,indexa) in bussoption" :key="indexa"  @click="navBar(item,indexa)">
                        <i :class="item.icon"></i>
                        <span slot="title" :class="(item.name.length === 3 ? 'ws24' : '')">{{item.name}}</span>
                    </el-menu-item>	

                </el-menu>
                
            </div>

            <!-- 数据部分 -->
            <div class="d_x-c-details">

                <div class="d_x-c-d-title">
                    <!-- <h1>商户录入后台</h1> -->
                    <span>
                        <span v-if="bussdata.level === 1">管理员</span>
                        <span v-else>{{ bussdata.level-1 | changestate }}</span>
                        ：<span class="bcfb br3 p5">{{ bussdata.name }}</span>
                    </span>
                    <span class="ff53 f24" @click="exitLogin"><i class="el-icon-error"></i></span>
                </div>

                <!-- 数据内容，使用路由跳转 -->
                <div class="d_x-c-d-details"><router-view></router-view></div>

            </div>

        </div>
    </div>
</template>

<script>
import axjs from "./js/request.js"
let Base64 = require('js-base64').Base64;
export default {
    data(){
        return{
            // 登录的账号密码数组
            login:{uname:'',pwd:'',state:false,text:''},
            //侧边栏的数组
            navioption:[	
                {id:1,name:"代理管理",link: '/agent',icon:'el-icon-s-custom'},
                {id:2,name:"类目管理",link: '/classify',icon:'el-icon-s-order'},										
                {id:3,name:"员工管理",link: '/manage',icon:'el-icon-user'},								
                {id:4,name:"门店管理",link: '/shops',icon:'el-icon-s-shop'},
                {id:5,name:"通 知",link: '/inform',icon:'el-icon-message-solid'},
            ],
            bussoption:[
                {id:1,name:"代理管理",link: '/business',icon:'el-icon-s-custom'},
                {id:2,name:"员工管理",link: '/user',icon:'el-icon-user'},								
                {id:3,name:"门店管理",link: '/usershop',icon:'el-icon-s-shop'},
            ],
            examinestate:false,
            typepwd: 'password',
            bussdata: null
        }
    },
    filters: {
        changestate(id){
            if(id !== 0){
                var chnNumChar = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
                var chnUnitSection = ["", "万", "亿", "万亿", "亿亿"];
                var chnUnitChar = ["", "十", "百", "千"];
                var strIns = "", chnStr = "";
                var unitPos = 0;
                var zero = true;
                while (id > 0) {
                    var v = id % 10;
                    if (v === 0) {
                        if (!zero) {
                            zero = true;
                            chnStr = chnNumChar[v] + chnStr;
                        }
                    } else {
                        zero = false;
                        strIns = chnNumChar[v];
                        strIns += chnUnitChar[unitPos];
                        chnStr = strIns + chnStr;
                    }
                    unitPos++;
                    id = Math.floor(id / 10);
                }
                return chnStr+"级代理";
            }
        },
    },
    methods: {
        exitLogin(){
            sessionStorage.removeItem("bussdata")
            this.$router.push("/")
            // for(var i in this.login)  this.login[i] = ""
            this.bussdata = ""
            // window.location.pathname = '/'
        },
        // 登录按钮
        register(){
            const that = this;
            // let axios = require('axios');
            let data = {list_rows:50,page:1,name:that.login.uname,password:that.login.pwd}
            // let updata = JSON.stringify(data)
            var timeId;
            axjs.request("/aLiPayBusiness/list","post",JSON.stringify(data)).then(resp=>{
                console.log(resp)
                let data = resp.data.data.data
                if(data.length !== 0){
                    that.login.text = "验证成功"
                    // that.login.state = true;
                    resp.data.data.data[0].level > 1 
                    ? this.$router.push("/business")
                    : this.$router.push("/agent");
                    that.bussdata = resp.data.data.data[0]
                    sessionStorage.setItem('bussdata', Base64.encode(JSON.stringify(resp.data.data.data[0])));
                    this.$message({
                        message: "登录成功",
                        type: "success"
                    })
                }else{
                    that.login.text = "账号或密码错误"
                    window.clearInterval(timeId);
                    timeId = window.setTimeout(() => {
                        that.login.text = ''
                    },3000)
                }
            })
            // axios({
            //     method: 'post',
            //     url: '/api/api/dh_school/b_login.php',
            //     headers: { "Content-Type": "appliction/JSON" },
            //     data: updata
            // })
            // .then( resp=> {
            //     // console.log(resp)
            //     let data = resp.data.data
            //     if(data.namestatus != 0 && data.passwordstatus !=0){
            //         that.login.text = "验证成功"
            //         that.login.state = true;
            //         sessionStorage.setItem('dh_xgj_login', JSON.stringify(that.login))
            //     }else{
            //         that.login.text = "您所输入的账号或密码不正确"
            //         window.clearInterval(timeId);
            //         timeId = window.setTimeout(() => {
            //             that.login.text = ''
            //         },3000)
            //     }
            // })
            // .catch( err=> { 
            //     // console.log(err)
            // })
        },
        // 密码框的输入事件
        examine(){
            const that = this;
            that.examinestate = true
            if(that.login.pwd === ''){
                that.examinestate = false
            }
        },
        // 查看密码
        checkpwd(){
            const that = this;
            if(that.typepwd === ''){
                that.typepwd = 'password'
            }else{
                that.typepwd = ''
            }
        },
        // 侧边栏函数
        handleSelect(key, keyPath) {},
        // 侧边栏函数
        navBar(item,indexa){
            // console.log(this.navioption[1].name.length)
        }
    },
    computed: {},
    watch: {},
    created() {
        const that = this;
        that.activerouter = window.location.pathname;
		// console.log(this.activerouter)
		//在页面加载时读取sessionStorage里的状态信息
		if (sessionStorage.getItem("bussdata")) {
			that.bussdata = JSON.parse(Base64.decode(sessionStorage.getItem("bussdata")))
		}
		//用事件句柄监听，在页面刷新时将vuex里的信息保存到sessionStorage里
		// console.log(this.login.checked)
		if(that.login.checked === true){
			// console.log("成功运行")
			window.addEventListener("beforeunload", () => {
				sessionStorage.setItem("dh_xgj_login", JSON.stringify(this.login));
			});
        }else{return}
        
    },
    mounted() {},
    beforeCreate() {},
    beforeMount() {},
    beforeUpdate() {},
    updated() {},
    beforeDestroy() {},
    destroyed() {},
    activated() {},
}
</script>

<style>
    button{
        outline: none;
        border: 0;
    }
    img{
        max-width: 100%;
        max-height: 100%;
    }
    #app {
        width: 100%;
        /* min-height: 937px; */
        min-height: 100vh;
        font-family: Helvetica, sans-serif;
        /* text-align: center; */
    }
    a{
        text-decoration:none
    }
    /* 登录跟成功登录的页面效果一样 */
    .dh_xgj-register,.dh_xgj-content{
        display: flex;
        /* justify-content: center; */
        /* min-height: 937px; */
        min-height: 100vh;
        background: url(assets/bgcimg.png) no-repeat;
        background-size: 100% 100%;
    }
    /* 登录框 */
    .d_x-reg-form{
        width: 260px;
        height: 230px;
        margin: auto;
        padding: 40px 50px;
		background-color: rgba(218, 199, 199, 0.3);
		border-radius: 10px;
		box-shadow: 1px 1px 8px 2px #000000;
    }
    .d_x-reg-form>h3{
        font-size: 18px;
        font-weight: 600;
        /* color: #0087c5; */
        color: white;
		text-shadow: 1px 1px 2px #000000;
    }
    /* 账号和密码 */
    .d_x-r-f-text{
        overflow: hidden;
        position: relative;
        display: flex;
        align-items: center;
        height: 40px;
        margin-top:20px;
        background-color: #fff;
        border-radius: 8px;
    }
    /* 图标 */
    .dx-rft-log{
        display: inline-block;
		width: 25px;
		height: 25px;
		margin: 0 5px;
    }
    div.d_x-r-f-text>i.unameicon{
        background: url(assets/uname.png) no-repeat 100% 100%;
    }
    div.d_x-r-f-text>i.pwdicon{
        background: url(assets/pwd.png) no-repeat 100% 100%;
    }
    /* 查看密码的图标 */
    .dx-rft-eye{
        z-index: 10000;
        position: relative;
        width: 20px;
		height: 20px;
		margin: 0 5px;
        background: url(assets/eye.png) no-repeat 100% 100%;
        background-size: 100% 100%;
    }
    /* 输入框 */
    .d_x-r-f-text>input{
        width: calc(100% - 69px);
        color: #0087c5;
		border: 0;
		outline: none;
    }
    input:focus,
	input:focus+i {
		color: #0087c5;
	}
    input:focus~.dx-rft-label {
		border: 1px solid #0087c5;
	}
    .dx-rft-label{
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		margin: 0;
		border: 1px solid rgb(187, 187, 187);
		border-radius: 5px;
	}
    /* 登录验证的提示信息 */
    .d_x-r-f-btn{
        text-align: left;
        font-size: 14px;
        height: 21px;
        text-shadow: 1px 1px 2px rgb(0, 0, 0);
        margin: 10px 0 10px;
        color: #ffff;
        border: 1px solid transparent;
    }
    /* 确认按钮 */
    form.d_x-reg-form>.el-button{
        width: 100%;
        height: 40px;
        padding: 0;
        font-size: 18px;
        color: black;
        border: 0;
        border-radius: 8px;
    }

    /* 后台数据样式   侧边栏*/
    .d_x-c-navigation{
        /* width: 130px; */
        font-size: 16px;
        min-height: 100%;
    }
    div.d_x-c-navigation>ul.el-menu{
        /* background-color: transparent; */
        height: 100%;
        border-right: 0;
    }

    .el-menu-item.is-disabled{
        opacity: 1;
        font-size: 18px;
        color: #21b8fd;
        cursor: auto;
    }

    /* 导航栏选中状态 */
    div>.d_x-c-navigation>ul.el-menu>.el-menu-item.is-active {
		background-color: #2caae4 !important;
		color: rgb(0, 110, 255);
        font-weight: 600;
        box-shadow: 1px 1px 10px rgb(95, 95, 95);
	}
    li.el-menu-item:hover{
        background-color: transparent;
    }
    li.el-menu-item{
        color: white;
    }
    /* 数据部分的样式 */
    .d_x-c-details{
        width: calc(100% - 166px);
        min-height: 100%;
    }
    .d_x-c-d-title{
        text-align: right;
        height: 56px;
        padding-right: 10px;
        line-height: 56px;
        color: white;
        /* font-weight: 600; */
        /* font-size: 18px; */
        text-shadow: 1px 1px 1px rgb(82, 82, 82);
        box-shadow: 11px 1px 10px rgb(12, 12, 12);
        background-color: rgb(32, 34, 42);
    }
    /* 列表数据 */
    .d_x-c-d-details{
        height: calc(100% - 56px);
        padding: 20px;
        background-color: rgb(240, 240, 240);
        box-sizing: border-box;
    }

    /* 上传图片的样式修改，全局属性 */
    /* upload上传图片的选框大小 */
    .el-upload--picture-card{
    border: 1px dashed #13C3C7;
    }
    .el-upload--picture-card:hover {
    border-color: #13C3C7;
    color: #13C3C7;
    }
    .el-upload--picture-card{
    width: 100px;
    height: 100px;
    font-size: 16px !important;
    }
    .el-upload{
    width: 100px;
    height: 100px;
    line-height: 100px;
    font-size: 16px;
    }
    .el-upload-list--picture-card .el-upload-list__item{
    width: 100px;
    height: 100px;
    /* line-height: 100px; */
    font-size: 16px;
    }

    .el-upload-list--picture-card .el-upload-list__item-actions:hover {
    opacity: 1;
    font-size: 16px;
    }

    .el-upload-list--picture-card .el-upload-list__item-thumbnail{
    width: 100px;
    height: 100px;
    line-height: 100px;
    font-size: 16px;
    }
    .avatar{
    width: 100px;
    height: 100px;
    }
</style>
